import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-03-28
 * Time: 9:37
 */
public class test07 {
    public static void main(String[] args) throws IOException {
        BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
        String str1 = null;
        String str2 = null;
        while ((str1 = b.readLine()) != null){
            str2 = b.readLine();
            if(str1.length() < str2.length()){
                System.out.println(findSub(str1,str2));
            }else {
                System.out.println(findSub(str2,str1));
            }

        }

    }
    public static String findSub(String str1,String str2){
        char[] a1 = str1.toCharArray();
        char[] a2 = str2.toCharArray();
        int size = 0;
        int maxlength = 0;
        int[][] len = new int[str1.length() + 1][str2.length() + 1];
        for (int i = 1; i <= str1.length(); i++) {
            for (int j = 1; j <= str2.length(); j++) {
                if(a1[i - 1] == a2[j - 1]) {
                    len[i][j] = len[i - 1][j - 1] + 1;
                }
                if (len[i][j] > maxlength) {
                    maxlength = len[i][j];
                    size = i - maxlength;
                }

            }
        }
        return str1.substring(size,size + maxlength);
    }
}
